package org.example.T;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
//注解这个类是接受ioc容器管理的bean
@Controller
@Component
public class Mother extends Person {
    private Father father;
//为了能找到爸爸setter方法，这里也可以通过构造方法注入但是配置文件标签就是<constructor-arg ref="father"/>
    //含义就是你要将father这个自动注入进来。
    @Autowired
    public void setFather(Father father) {
        this.father = father;
    }

//    public Mother(Father father){
//       this.father = father;
//    }
    //妈妈做饭
    public boolean cook(){
        try {
            prepare();
        }catch (RuntimeException e){
            father.bySalt();
        }
        System.out.println(this.getName()+"继续做饭.....");
        System.out.println(this.getName()+"成功煮饭");
        return true;
    }
    //妈妈准备做饭
    public void prepare()throws RuntimeException{
        System.out.println(this.getName()+"准备做饭");
        System.out.println(this.getName()+"发现没有酱油了");
        throw new RuntimeException("发现没有酱油了");
    }

}
